package com.uphone.kingmall.adapter;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.blankj.utilcode.util.SizeUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.china.zhuoyue.R;
import com.uphone.kingmall.bean.GoodsListBean;
import com.uphone.kingmall.utils.GlideUtils;

/**
 * Created by tzh on 2020/6/11.
 */
public class GoodsListAdapter extends BaseQuickAdapter<GoodsListBean.DataBean, BaseViewHolder> {
    private AddGoodsListener mListener;

    public GoodsListAdapter(int layoutId) {
        super(layoutId);
    }

    @Override
    protected void convert(final BaseViewHolder helper, final GoodsListBean.DataBean item) {
        ImageView icon = helper.getView(R.id.iv_icon);
        TextView tv_goods_count = helper.getView(R.id.tv_goods_count);
        GlideUtils.getInstance().loadCornerImage(mContext, item.getGoodsMainImg(), SizeUtils.dp2px(2), icon);
        helper.setText(R.id.tv_name, item.getGoodsName());
        helper.setText(R.id.tv_price, "¥" + item.getGoodsPrice());
        helper.setText(R.id.tv_yue_xiao, "月销" + item.getGoodsSaleNum());
        if (item.shopCarGoodsNum > 0) {
            tv_goods_count.setText(String.valueOf(item.shopCarGoodsNum));
            tv_goods_count.setVisibility(View.VISIBLE);
        } else {
            tv_goods_count.setVisibility(View.GONE);
        }
        //添加到购物车
        helper.getView(R.id.v_add_to_car).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mListener != null) mListener.onAddClick(item);
            }
        });
    }

    public interface AddGoodsListener {
        void onAddClick(GoodsListBean.DataBean bean);
    }

    public void setAddGoodsListener(AddGoodsListener mListener) {
        this.mListener = mListener;
    }

}
